package org.lu.plugins.activity;

import android.content.Intent;
import com.bstek.tool.SimpleActivity;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by ilulu on 14-7-16.
 */
public class ActivityPlugin extends CordovaPlugin {
    @Override
    public boolean execute(String action,  JSONArray args, CallbackContext callbackContext) throws JSONException {
        if(action.equals("openPage")){
            JSONObject param=args.getJSONObject(0);
            String path=(String)param.get("path");
            Intent intent=new Intent(cordova.getActivity(), SimpleActivity.class);
            intent.putExtra("path", path);
            intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            cordova.startActivityForResult(this,intent,0);
            callbackContext.success("success");
            return true;
        }else  if(action.equals("closePage")){
            cordova.getActivity().setResult(0);
            cordova.getActivity().finish();
            callbackContext.success("success");
            return true;
        }
        return false;
    }
}
